package com.bwsoft.api.action;

import java.io.IOException;
import java.util.Calendar;
import java.util.Map;

import org.apache.log4j.Logger;

import com.bwsoft.api.pojo.ResponsePojo;

public class DictionaryAction extends ApiBaseAction<DictionaryAction> {
	private static Logger LOG = Logger.getLogger(DictionaryAction.class);
	
	private String dicName;
	
	/**
	 * 2.1.3 获取字典
	 * @return
	 * @throws Exception 
	 * @throws IOException 
	 */
	@SuppressWarnings("unchecked")
	public void data() throws IOException, Exception {
		LOG.info("=================================开始调用【2.1.3 获取字典 】==============================");
		try{
		//得到调用接口开始时的毫秒数
		beginTimestamp=Calendar.getInstance().getTimeInMillis();
		Boolean canFlag=true;
		LOG.info("传入参数r="+super.getR());
		if(r==null||r.trim().equals("")){
			responseJson.put("errcode", 1);
			responseJson.put("errmsg", "r值不能为空");
			finishMethod();
			LOG.info("=======================================传入参数r为空，提前结束");
		}
		Map<String, Object> parameMap= reflexParameters();

			if (!parameMap.isEmpty() && parameMap.containsKey("dicName")&&!parameMap.get("dicName").equals(""))
				dicName = (String) parameMap.get("dicName");
		
		
		if (canFlag) {
			// 调用service方法得到要返回的数据对象
			LOG.info("开始调用取数方法");
			ResponsePojo rp = dictionaryService.getData(dicName);
			LOG.info("调用取数方法结束");
			responseJson.put("errcode", rp.getErrcode());
			responseJson.put("errmsg", rp.getErrmsg());
			responseJson.put("data", rp.getData());
		}
		}catch (Exception e) {
			e.printStackTrace();
			responseJson.put("errcode", 5000);
			responseJson.put("errmsg", "服务器异常");
			LOG.info("【2.1.3 获取字典】异常"+e);
		}
		finishMethod();
		LOG.info("=================================调用结束【2.1.3 获取字典】==============================");
	}	
}
